package com.unittec.zk.provider.work.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.unittec.zk.provider.utils.CopyUtils;
import com.unittec.zk.sdk.work.request.Req202001;
import com.unittec.zk.sdk.work.request.Req202002;
import com.unittec.zk.sdk.work.request.Req202003;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.unittec.zk.provider.work.mapper.CarInfoMapper;
import com.unittec.zk.provider.work.entity.CarInfo;

@Service
public class CarInfoService extends ServiceImpl<CarInfoMapper, CarInfo> {

    /**
     * 车辆信息-分页
     *
     * @param req202001
     * @return
     */
    public Object getCarPage(Req202001 req202001) {
        LambdaQueryWrapper<CarInfo> qw = new LambdaQueryWrapper<>();
        if (StrUtil.isNotBlank(req202001.getTruckNumber())) {
            qw.like(CarInfo::getTruckNumber, req202001.getTruckNumber());
        }
        if (StrUtil.isNotBlank(req202001.getTruckBrand())) {
            qw.like(CarInfo::getTruckBrand, req202001.getTruckBrand());
        }
        if (req202001.getState() != null) {
            qw.eq(CarInfo::getState, req202001.getState());
        }
        if (req202001.getTruckType() != null) {
            qw.eq(CarInfo::getTruckType, req202001.getTruckType());
        }
        if (req202001.getIsHere() != null) {
            qw.eq(CarInfo::getIsHere, req202001.getIsHere());
        }
        qw.orderByDesc(CarInfo::getCreateTime);

        Page<CarInfo> page = this.page(new Page<>(req202001.getCurrent(), req202001.getSize()), qw);
        return page;
    }

    /**
     * 车辆信息-增/改
     * @param req202002
     * @return
     */
    public Object carSaveOrUpdate(Req202002 req202002) {
        CarInfo carInfo = new CarInfo();
        CopyUtils.copyProperties(req202002,carInfo);
        this.saveOrUpdate(carInfo);
        return "Success";
    }

    /**
     * 车辆信息-逻辑删
     * @param req202003
     * @return
     */
    public Object carInfoDelbyIds(Req202003 req202003) {
        this.removeByIds(req202003.getIds());
        return "Success";
    }
}
